<!DOCTYPE html>
<html>
<meta charset='utf-8'>
<title>Media History</title>
<video></video>
<script>
function attemptPlayVideo() {
  // This content has both an audio and a video track.
  attemptPlay('bigbuck.webm');
}

function attemptPlayAudioOnly() {
  // This content only has an audio track (no video).
  attemptPlay('audio-only.webm');
}

function attemptPlayVideoOnly() {
  // This content only has a video track (no audio).
  attemptPlay('video-only.webm');
}

function mute() {
  const video = document.querySelector('video');
  video.muted = true;
}

function attemptPlay(src) {
  const video = document.querySelector('video');
  video.src = src;

  video.play().then(() => {
    window.domAutomationController.send(true);
  }, function() {
    window.domAutomationController.send(false);
  });
}

function setMediaMetadata(artwork) {
  navigator.mediaSession.metadata = new MediaMetadata({
    title: 'Big Buck Bunny',
    artist: 'Test Footage',
    album: 'The Chrome Collection',
    artwork: artwork
  });
}

function setMediaMetadataWithArtwork() {
  setMediaMetadata([
      { src: '/artwork-96.png',  sizes: '96x96',   type: 'image/png' },
      { src: '/artwork-128.png', sizes: '128x128', type: 'image/png' },
      { src: '/artwork-big.jpg', sizes: '192x192 256x256', type: 'image/jpg' },
      { src: '/artwork-any.jpg', sizes: 'any', type: 'image/jpg' },
      { src: '/artwork-notype.jpg', sizes: 'any' },
      { src: '/artwork-nosize.jpg', type: 'image/jpg' }
  ]);
}

function setMediaMetadataWithAltArtwork() {
  setMediaMetadata([
      { src: '/artwork-96.png',  sizes: '96x96',   type: 'image/png' },
      { src: '/artwork-alt.png', sizes: '128x128', type: 'image/png' }
  ]);
}

function seekToFour() {
  const video = document.querySelector('video');
  video.currentTime = 4;
}

function waitForSignificantPlayback() {
  const video = document.querySelector('video');

  video.addEventListener('timeupdate', () => {
    if (video.currentTime > 7)
      window.domAutomationController.send(true);
  });
}

function finishPlaying() {
  const video = document.querySelector('video');
  video.currentTime = video.duration;
}

function enterPictureInPicture() {
  const video = document.querySelector('video');
  video.requestPictureInPicture().then(() => {
    window.domAutomationController.send(true);
  }).catch(() => {
    window.domAutomationController.send(false);
  });
}

</script>
</html>
